﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZWZ.Web.WebAdmin
{
    public partial class T : System.Web.UI.Page
    {
        string RawUrl { get { return Request["url"]; } }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsLocal) Response.Redirect(Config.ConfigAdapter.SiteDataMgr.Groups["Req_PageFile"].Settings["PageLogin"].Value);
            if (!IsPostBack)
            {
                DropDownList1.DataSource = DBProvider.DB.Ctx.User_Info.Select(i => new
                {
                    NickName = "【" + i.GroupName + "】 " + i.NickName,
                    i.Email
                });
                DropDownList1.DataBind();
                DropDownList1.SelectedIndex = 0;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            string supwd = Config.ConfigAdapter.SiteDataMgr.Groups["BaseSetting"].Settings["SupwdKey"].Value;
            string admindir = Config.ConfigAdapter.SiteDataMgr.Groups["Req_PageDir"].Settings["DirAdmin"].Value;
            try
            {
                if (Codes.LoginHelper.Login(DropDownList1.SelectedValue, supwd))
                {
                    //登录成功
                    if (!string.IsNullOrEmpty(RawUrl) && !RawUrl.Contains("/WebAdmin/t.aspx") && !RawUrl.Contains("/WebAdmin/l.aspx"))
                    {
                        admindir = RawUrl;
                    }
                    Codes.LoggerHelper.AdminLogger.Info("登录成功，用户："+Codes.LoginHelper.CurrentUser.NickName);
                    Response.Redirect(admindir,false);
                }
            }
            catch (Exception exp)
            {
                var MsgBox = new Codes.MessageBox(this);
                MsgBox.Show(exp.Message);
                Codes.LoggerHelper.AdminLogger.Error("测试登录错误", exp);
                MsgBox.Send();
            }
            
        }
    }
}